﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace QHY.Common
{
    public class qhy_AuthorizeAttribute : AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool result = false;
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }
            var user = httpContext.Session["UserName"];
            if (user != null)
            {
                if (user.Equals("andy"))
                {
                    result = true;
                }
            }
            else { result = false; }
           
          
            if (!result)
            {
                httpContext.Response.StatusCode = 403;
            }
            return result;
        }

        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);
            if (filterContext.HttpContext.Response.StatusCode == 403)
            {
                filterContext.Result = new RedirectResult("/Account/LogOn");
            }
        }



    }
}